package com.tanhua.server.controller;

import com.tanhua.server.service.SoundService;
import com.tanhua.server.vo.SoundVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author: lc
 * @Description:
 * @Date: Created in 10:39 2021/1/17
 * @ModifiedBy:
 */
@RestController
@RequestMapping("peachblossom")
public class SoundController {

    @Autowired
    private SoundService soundService;

    /**
     * @param soundFile
     * @return
     */
    @PostMapping
    public ResponseEntity<Object> sendSound(@RequestParam(value = "soundFile") MultipartFile soundFile) {

        try {
            Boolean bo = this.soundService.sendSound(soundFile);
            if (bo) {
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 接收语音
     *
     * @return
     */
    @GetMapping
    public ResponseEntity<SoundVo> querySound() {

        try {
            //创建SoundVo对象
            SoundVo soundVo = new SoundVo();
            if (soundVo != null) {
                //不为空返回
                return ResponseEntity.ok(soundVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

}
